import { Controller, Post, Body } from "@nestjs/common";
import { CollectAddDto, CollectRemoveDto, CollectUpdateDto, CollectQueryDto } from "src/dto/collect";
import { CollectService } from "../service/collect.service";
import { ApiRes, RequsetUser, UsePermGuard, definePermission } from "src/decorator";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { CollectEntity } from "src/entity";

const Perm = definePermission("user:collect", {
    query: {
        name: "查询",
        code: "query",
        description: "用户收藏查询权限",
    },
    add: {
        name: "添加",
        code: "add",
        description: "用户收藏添加权限",
    },
    update: {
        name: "更新",
        code: "update",
        description: "用户收藏更新权限",
    },
    remove: {
        name: "移除",
        code: "remove",
        description: "用户收藏移除权限",
    },
} as const);

@ApiTags("User - 模块", "Collect - 模块")
@Controller("user")
export class CollectController {
    constructor(private readonly collectService: CollectService) {}

    @ApiOperation({ summary: "收藏列表" })
    @ApiRes({ type: CollectEntity, pagination: true })
    @UsePermGuard(Perm.QUERY)
    @Post("query_collect")
    queryCollect(@RequsetUser("id") id: number, @Body() collect: CollectQueryDto) {
        return this.collectService.query(id, collect);
    }

    @ApiOperation({ summary: "添加收藏" })
    @ApiRes({ type: CollectEntity })
    @UsePermGuard(Perm.ADD)
    @Post("add_collect")
    addCollect(@RequsetUser("id") id: number, @Body() collect: CollectAddDto) {
        return this.collectService.add(id, collect);
    }

    @ApiOperation({ summary: "更新收藏" })
    @UsePermGuard(Perm.UPDATE)
    @Post("update_collect")
    updateCollect(@RequsetUser("id") id: number, @Body() collect: CollectUpdateDto) {
        return this.collectService.update(id, collect);
    }

    @ApiOperation({ summary: "移除收藏" })
    @UsePermGuard(Perm.REMOVE)
    @Post("remove_collect")
    removeCollect(@RequsetUser("id") id: number, @Body() collect: CollectRemoveDto) {
        return this.collectService.remove(id, collect);
    }
}
